package durst.action.account;

import java.sql.SQLException;
import java.util.List;

import net.sourceforge.stripes.action.DefaultHandler;
import net.sourceforge.stripes.action.RedirectResolution;
import net.sourceforge.stripes.action.Resolution;
import net.sourceforge.stripes.validation.Validate;
import net.sourceforge.stripes.validation.ValidateNestedProperties;
import durst.action.CalendarBasicAction;
import durst.data.Account;
import durst.data.Friend;
import durst.data.dao.DaoFactory;
import durst.data.dao.impl.FriendDao;

public class RemoveFriendsAction extends CalendarBasicAction {
	@ValidateNestedProperties(@Validate(field="id", required=true))
	private List<Account> friends; 
	
	@SuppressWarnings("unchecked")
	@DefaultHandler
	public Resolution handle() throws SQLException {
		((FriendDao<Friend, Integer>)DaoFactory.getInstance().createDao(Friend.class)).deleteFriends(context.getAccount(), friends);
		return new RedirectResolution(ManageAccountActionBean.class);
	}

	public void setFriends(List<Account> friends) {
		this.friends = friends;
	}

	public List<Account> getFriends() {
		return friends;
	}
}
